import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import './loading.css'
import app from '../../main';

export default class Loading2 extends Component {

    config = {
        navigationBarBackgroundColor: "#000000",
        navigationBarTextStyle: "white",
        navigationBarTitleText: ''
    }

    constructor(){
        super(...arguments);
        this.state = {
            loading:'https://zhongsheng.bayou-tech.cn/img/imgs/jiazai3.gif',
        }
    }

    componentWillMount(){
        let me = this

        Taro.uploadFile({
            url: app.apiUri + '/admin/upload/image',
            filePath: me.$router.params.src,
            name: 'file',
            formData: {
                name: 'file'
            },
            success(res) {            
                let data = JSON.parse(res.data);
                if (data.status == 200) {
                    app.eyesphoto = data.result

                    let date = {
                        path: data.result
                    }

                    app.post('api/tencent_ai/check_face', date, function(res){
                        if(res.data.result.ret == 0){
                            if(me.$router.params.id == 10){
                                app.redirectTo('../determine/Determine?id=' + '10')
                            }else if(me.$router.params.id == 20){
                                app.redirectTo('../determine/Determine?id=' + '20')                               
                            }else{
                                app.redirectTo('../determine/Determine')
                            }
                        }else{
                            app.redirectTo('../fail/fail')
                        }
                    })

                                     
                }
            }               
        })                    
    }

    render () {
        return (
            <View className='image-text'>
                <View><Image className='i'src={this.state.loading}/></View>
                <View className='text'>识别中</View>
            </View>   
        )
    }
}